import { createSlice } from '@reduxjs/toolkit'
import { copyData } from '@/util/util'

let initialState = {
  avatar: '',
  email: '',
  id: '',
  realname: '',
  status: '',
  username: ''
}

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    addState: (state, { payload }) => {
      copyData(state, payload)
    },
    deleteState: state => {
      const keyArr = Object.keys(state)
      for (const key in keyArr) {
        keyArr[key] = ''
      }
    }
  }
})
export const { addState } = userSlice.actions
export default userSlice.reducer
